package com.travel.controller;

import com.travel.pojo.TravelCarousel;
import com.travel.result.Result;
import com.travel.service.TravelCarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "后台管理-轮播图管理")
@RestController
@RequestMapping("/travel/carousel")
public class TravelCarouselController {
    @Autowired
    private TravelCarouselService travelCarouselService;

    @ApiOperation("获取轮播图列表")
    @GetMapping("/list")
    public Result<Object> getCarouselList() {
        return Result.success(travelCarouselService.list());
    }

    @ApiOperation("新增轮播图")
    @PostMapping("/add")
    public Result<Object> addCarousel(@RequestBody TravelCarousel travelCarousel) {
        travelCarouselService.save(travelCarousel);
        return Result.success("新增成功");
    }

    @ApiOperation("删除轮播图")
    @DeleteMapping("/delete/{id}")
    public Result<Object> deleteCarousel( @PathVariable Integer id) {
        travelCarouselService.removeById(id);
        return Result.success("删除成功");
    }

    @ApiOperation("修改轮播图")
    @PutMapping("/update/{id}")
    public Result<Object> updateCarousel( @PathVariable Integer id, @RequestBody TravelCarousel travelCarousel) {
        travelCarousel.setId(id);
        travelCarouselService.updateById(travelCarousel);
        return Result.success("修改成功");
    }
}
